package com.bnlr.lrparking.adapter;

import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.bnlr.lrparking.R;
import com.bnlr.lrparking.model.MyPublishBean;
import com.bnlr.lrparking.view.CarCommon;

import java.util.List;

/**
 * Created by tian on 2017/10/26.
 */

public class PersonPostAdapter extends BaseMultiItemQuickAdapter<MyPublishBean.DataBean,BaseViewHolder> {

    public PersonPostAdapter(List<MyPublishBean.DataBean> data) {
        super(data);
        addItemType(MyPublishBean.DataBean.CHU_ZU, R.layout.item_stalldeal);
        addItemType(MyPublishBean.DataBean.CHU_SHOU, R.layout.item_stalldeal);
        addItemType(MyPublishBean.DataBean.QIU_ZU, R.layout.item_stallrentbuy);
        addItemType(MyPublishBean.DataBean.QIU_GOU, R.layout.item_stallrentbuy);
    }

    @Override
    protected void convert(BaseViewHolder helper, MyPublishBean.DataBean item) {
        switch (helper.getItemViewType()) {
            case MyPublishBean.DataBean.CHU_ZU:
            case MyPublishBean.DataBean.CHU_SHOU:
                Glide.with(mContext).load(item.getPhotoUrl())
                        .placeholder(R.mipmap.tab2_defaultgraph)
                        .error(R.mipmap.tab2_defaultgraph)
                        .into((ImageView) helper.getView(R.id.stall_deal_iv));
                helper.setText(R.id.item_type,item.getStatus());
                helper.setText(R.id.tv_stalldeal_title,item.getTitle());
                helper.setText(R.id.tv_stalldeal_size,item.getSize()+"㎡");
                helper.setText(R.id.tv_stalldeal_address,item.getArea());
                helper.setText(R.id.tv_rentbuy,item.getCreateTime().split(" ")[0]);
                helper.setText(R.id.tv_stalldeal_address_deilsa,item.getAddress());
                helper.setText(R.id.tv_stalldeal_price,item.getPrice());
                if (item.getSpaceOwerType() == 1) {
                    helper.setText(R.id.tv_stalldeal_type,"开发商");
                }
                break;
            case MyPublishBean.DataBean.QIU_ZU:
            case MyPublishBean.DataBean.QIU_GOU:
                helper.setVisible(R.id.ll_phone,false);
                helper.setText(R.id.item_type,item.getStatus());
                helper.setText(R.id.tv_stalldeal_title,item.getTitle());
                helper.setText(R.id.tv_stalldeal_address_deilsa,item.getAddress());
                helper.setText(R.id.tv_rentbuy,item.getCreateTime().split(" ")[0]);
                helper.setText(R.id.tv_stalldeal_price,item.getPrice());
                ImageView ivPhone = helper.getView(R.id.img_rentbuy_phone);
                ivPhone.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        CarCommon carCommon = new CarCommon();
                        carCommon.phoneDialog(mContext);
                    }
                });
                break;
            default:
                break;
        }
    }
}
